<?php
declare (strict_types = 1);

namespace app\api\model\v1;

use think\Model;

/**
 * @mixin \think\Model
 */
class Learn extends AppModel
{
    //



    public static function saveImportExcel($arrData,$uid){
        if (empty($arrData)) {
            $result = 500;
        }else{
            foreach ($arrData as $key=>$value){
               $learn_id = self::create([
                    'title'=>$value['title'],
                    'create_id'=>$uid
                ])->id;
                if (isset($value['item'])) { //判断是否包含item字段
                    //如果包含item字段 循环
                    foreach ($value['item'] as $child_key => $child_value) {
                            $learn_topic_id = LearnTopic::create([
                                'topic_title'=>$child_value['topic_title'], //标题
                                'learn_id'=>$learn_id, //id
                                'learn_answer'=>$child_value['learn_answer'],
                                'question_type'=>$child_value['question_type'],
                                'answer_explain'=>$child_value['answer_explain'],
                                'create_id'=>$uid
                            ])->id;
                        if (isset($child_value['item'])) {
                            foreach ($child_value['item'] as $child_child_key => $child_child_value) {
                                LearnOption::create([
                                    'option_title'=>$child_child_value['option_title'], //标题
                                    'learn_id'=>$learn_id, //id
                                    'learn_topic_id'=>$learn_topic_id,
                                    'create_id'=>$uid
                                ]);
                            }
                        }
                    }
                }
            }
            $result = 200;
        }
        return $result;
    }
}
